package com.ccb.sc.order.vo;

import com.ccb.sc.member.vo.ReceiverVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ken
 * @version 1.0
 * @date 2020-09-26
 */
@Data
@ApiModel(value = "订单预览")
public class OrderPreviewVo implements Serializable {

    @ApiModelProperty("商品id")
    private Long goodsId;

    @ApiModelProperty("收货地址列表")
    private List<ReceiverVo> receivers;

    @ApiModelProperty("商品项")
    private List<ShoppingCartItemVo> orderItems = new ArrayList<>();

    @ApiModelProperty("积分余额")
    private Integer balance;

    @ApiModelProperty("余额")
    private BigDecimal amountBalance = BigDecimal.ZERO;

    @ApiModelProperty("是否团购")
    private Boolean isGroupon = Boolean.FALSE;

    @ApiModelProperty("订单合计积分")
    public int getOrderTotalPoints() {
        int totalPoints = 0;
        for (ShoppingCartItemVo orderItem : orderItems) {
            totalPoints = totalPoints + orderItem.getSubtotalExchangePoints();
        }
        return totalPoints;
    }

    @ApiModelProperty("订单合计金额")
    public BigDecimal getOrderTotalAmount() {
        BigDecimal totalPoints = BigDecimal.ZERO;
        for (ShoppingCartItemVo orderItem : orderItems) {
            totalPoints = totalPoints.add(orderItem.getSubtotalAmount());
        }
        return totalPoints;
    }
}
